package scrum.client.project;

import ilarkesto.core.base.Utl;
import ilarkesto.core.scope.Scope;

import java.util.Comparator;
import java.util.Map;

import scrum.client.ScrumGwt;
import scrum.client.admin.Auth;
import scrum.client.common.LabelSupport;
import scrum.client.common.ReferenceSupport;

public class ProjectGroup extends GProjectGroup implements ReferenceSupport, LabelSupport, /* ForumSupport, */
Comparable<ProjectGroup> {

	public static final String REFERENCE_PREFIX = "pgr";

	public ProjectGroup(Project project) {
		setProject(project);
	}

	public ProjectGroup(Map data) {
		super(data);
	}

	@Override
	public String getReference() {
		return REFERENCE_PREFIX + getNumber();
	}

	@Override
	public String toHtml() {
		return ScrumGwt.toHtml(this, getLabel());
	}

	@Override
	public String toString() {
		return getReference() + " " + getLabel();
	}

	@Override
	public int compareTo(ProjectGroup o) {
		return Utl.compare(getLabel(), o.getLabel());
	}

	@Override
	public boolean isEditable() {
		if (!getProject().isProductOwner(Scope.get().getComponent(Auth.class).getUser())) return false;
		return true;
	}

	// @Override
	// public Widget createForumItemWidget() {
	// return new HyperlinkWidget(new ShowEntityAction(QualityBacklogWidget.class, this, getLabel()));
	// }

	public static final Comparator<ProjectGroup> LABEL_COMPARATOR = new Comparator<ProjectGroup>() {

		@Override
		public int compare(ProjectGroup a, ProjectGroup b) {
			return Utl.compare(a.getLabel(), b.getLabel());
		}
	};
}